package com.starry.module.system.core.logger.controller.admin;

import cn.hutool.http.HttpStatus;
import com.starry.core.common.domain.R;
import com.starry.core.common.domain.vo.PageVo;
import com.starry.core.web.core.controller.BaseController;
import com.starry.module.system.api.logger.domain.qo.SysLogOperationPageQo;
import com.starry.module.system.api.logger.domain.qo.SysLogOperationQo;
import com.starry.module.system.api.logger.domain.vo.SysLogOperationVo;
import com.starry.module.system.core.logger.service.SysLogOperationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * 操作日志
 * @author xiaoke
 */
@Tag(name = "操作日志")
@RestController
@RequestMapping("system/sysLogOperation")
public class SysLogOperationController extends BaseController {

    private final SysLogOperationService sysLogOperationService;

    public SysLogOperationController(SysLogOperationService sysLogOperationService) {
        this.sysLogOperationService = sysLogOperationService;
    }

    /**
     * 分页查询
     *
     * @param pageQo 查询实体
     * @return 所有数据
     */
    @Operation(summary = "操作日志-分页查询")
    @GetMapping("sysLogOperationPage")
    public R<PageVo<SysLogOperationVo>> findPage(SysLogOperationPageQo pageQo) {
        return success(this.sysLogOperationService.page(pageQo));
    }

    /**
     * 新增数据
     *
     * @param sysLogOperationQo 实体对象
     * @return 新增结果
     */
    @Operation(summary = "操作日志-新增")
    @PostMapping("sysLogOperationCreate")
    public R<Long> insert(@RequestBody @Validated SysLogOperationQo sysLogOperationQo) {
        return success(HttpStatus.HTTP_CREATED, this.sysLogOperationService.save(sysLogOperationQo));
    }

    /**
     * 删除数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "操作日志-删除")
    @PostMapping("sysLogOperationRemove")
    public R<Void> delete(@RequestParam("idList") Set<Long> idList) {
        this.sysLogOperationService.removeByIds(idList);
        return success();
    }
}

